#include "/node_modules/lygia/color/space.glsl"
#include "/node_modules/lygia/lighting/fresnel.glsl"
uniform vec3 uThemeColor;

uniform float iTime;
uniform vec3 iResolution;
uniform vec4 iMouse;
varying float vNoise;
varying vec3 vWorldPosition;
varying vec2 vUv;
varying vec3 vNormal;


vec3 palette(in float t,in vec3 a,in vec3 b,in vec3 c,in vec3 d)
{
    return a+b*cos(6.28318*(c*t+d));
}


void main(){
    vec2 uv=vUv;
    vec3 col=vec3(1.);
    // col=palette(vNoise,vec3(.5),vec3(.5),vec3(1.),vec3(0.,.10,.20));
    // float fres=fresnel(0.,1.,5.,viewDir,vNormal);

    vec3 viewDir=normalize(cameraPosition-vWorldPosition);
     vec3 fres=fresnel(uThemeColor,vNormal,viewDir);
     col=fres;

        // col=linear2gamma(col);
    col=linear2gamma(col);
    vec3 lightColor=vec3(1.,0.,0.);
    vec3 lightPos=vec3(10.,10.,10.);
    float diff=max(dot(vNormal,normalize(lightPos-vWorldPosition)),0.);
     col=mix(col,lightColor,diff*fres);

      vec3 lightColor2=vec3(0.,0.5,1.);
    vec3 lightPos2=vec3(-10.,-10.,10.);
    float diff2=max(dot(vNormal,normalize(lightPos2-vWorldPosition)),0.);
     col=mix(col,lightColor2,diff2*fres);
    gl_FragColor=vec4(col,1.);
}